<!DOCTYPE html>
<html lang="zh-CN" xmlns:th=http://www.thymeleaf.org>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ATC | Config</title>
    <link href="inspinia/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" th:href="@{inspinia/font-awesome-4.7.0/css/font-awesome.min.css}"/>
    <link href="inspinia/css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <link href="inspinia/js/plugins/gritter/jquery.gritter.css" rel="stylesheet">
    <link href="inspinia/css/animate.css" rel="stylesheet">
    <link href="inspinia/css/style.css" rel="stylesheet">
    <link th:href="@{inspinia/css/jquery.mloading.css}" rel="stylesheet">
    <link th:href="@{inspinia/css/jquery-confirm.css}" rel="stylesheet">
</head>
<body class="gray-bg" style="width:65%;margin-left:15%">
<div class="animated fadeInDown">
    <div id="main-body">
        <h1>参数配置</h1>
        <div class="hr-line-dashed"></div>
        <form method="post" th:object="${config}"
              action="#"
              onsubmit="saveConfig()"
              role="form"
              class="form-horizontal">
            <div class="modal-body">
                <div class="row">
                    <div class="col-lg-10">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">项目路径：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" th:field="*{WORKSPACEPROPATH}"
                                       placeholder="eg: //C://MyEclipse Professional 2016//MYPRONAME"
                                       th:text="${WORKSPACEPROPATH}" class="form-control" required="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">SRC根路径：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" th:field="*{SRCPATH}"
                                       placeholder="maven: //src//main//java    JAVA://src"
                                       th:text="${SRCPATH}" class="form-control" required="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">WEBAPP根路径：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" th:field="*{WEBSRCPATH}"
                                       placeholder="maven: //src//main//webapp"
                                       th:text="${WEBSRCPATH}" class="form-control" required="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">JS根路径：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" th:field="*{JSSRCPATH}"
                                       placeholder="maven: //src//main//webapp"
                                       th:text="${JSSRCPATH}" class="form-control" required="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">页面路径：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" th:field="*{JSP_PACKAGE}"
                                       placeholder="eg: fold1.fold2"
                                       th:text="${JSP_PACKAGE}" class="form-control" required="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">Controller包名：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" th:field="*{CONTROLLER_PACKAGE}"
                                       placeholder="eg: com.atc.controller"
                                       th:text="${CONTROLLER_PACKAGE}" class="form-control" required="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">Service包名：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" th:field="*{SERVICE_PACKAGE}"
                                       placeholder="eg: com.atc.service"
                                       th:text="${SERVICE_PACKAGE}" class="form-control" required="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">ServiceImpl包名：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" th:field="*{SERVICEIMPL_PACKAGE}"
                                       placeholder="eg: com.atc.service.impl"
                                       th:text="${SERVICEIMPL_PACKAGE}" class="form-control" required="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">Dao包名：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" th:field="*{DAO_PACKAGE}"
                                       placeholder="eg: com.atc.dao"
                                       th:text="${DAO_PACKAGE}" class="form-control" required="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">Mapping包名：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" th:field="*{MAPPING_PACKAGE}"
                                       placeholder="eg: com.atc.mapping"
                                       th:text="${MAPPING_PACKAGE}" class="form-control" required="">
                            </div>
                        </div>

                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" th:onclick="'javascript:goMain()'">
                    返回主页
                </button>
                <button type="submit" class="btn btn-primary">
                    提交参数
                </button>
            </div>
        </form>
    </div>
</div>
<!-- Mainly scripts -->
<script src="inspinia/js/jquery-3.1.1.min.js"></script>
<script src="inspinia/js/bootstrap.min.js"></script>
<script src="inspinia/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<!-- Custom and plugin javascript -->
<script src="inspinia/js/plugins/pace/pace.min.js"></script>
<!-- jQuery UI -->
<script src="inspinia/js/plugins/jquery-ui/jquery-ui.min.js"></script>
<!-- Toastr -->
<script src="inspinia/js/plugins/toastr/toastr.min.js"></script>
<!--jquery.form.js-->
<script src="inspinia/js/jquery.form.js"></script>
<!--jquery loading-->
<script src="inspinia/js/jquery.mloading.js"></script>
<!--jquery confirm-->
<script src="inspinia/js/jquery-confirm.js"></script>
<script th:inline="javascript">
    /*<![CDATA[*/
    $(document).ready(function () {
        $('.form-horizontal').ajaxForm();
    });

    function goMain() {
        window.location.href = getRootPath();
    }

    function saveConfig() {
        var options = {
            beforeSubmit: function () {
                showMLoading();
            },
//          提交后的回调函数
            success: function (data, statusText) {
                hideMLoading();
                if (data.flag) {
                    window.location.href = getRootPath();
                } else {
                    $.confirm({
                        title: '出错了', // hides the title.
                        content: data.msg,
                        cancelButton: '确定',
                        confirmButton: false, // hides the confirm button.
                        closeIcon: false, // hides the close icon.
                        content: false // hides content block.
                    });
                }
            },
            url: "config",
            type: "POST",    // 默认值是form的method("GET" or "POST")，如果声明，则会覆盖
            dataType: "json",    // html（默认）、xml、script、json接受服务器端返回的类型
            clearForm: true,    // 成功提交后，清除所有表单元素的值
            resetForm: true,    // 成功提交后，重置所有表单元素的值
            timeout: 3000000    // 限制请求的时间，当请求大于3秒后，跳出请求
        };
        $('.form-horizontal').ajaxSubmit(options);
        return false;
    }

    /**
     * 遮罩层显示
     */
    function showMLoading() {
        myMLoading = $.confirm({
//            icon: 'fa fa-spinner fa-spin',
            icon: 'fa fa-spinner fa-pulse',
            title: '加载中...', // hides the title.
            cancelButton: false, // hides the cancel button.
            confirmButton: false, // hides the confirm button.
            closeIcon: false, // hides the close icon.
            content: false // hides content block.
        });
    }

    /**
     * 遮罩层隐藏
     */
    function hideMLoading() {
        myMLoading.close();
    }

    /**
     * 获取项目根路径
     */
    function getRootPath() {
        var strFullPath = window.document.location.href;
        var strPath = document.location.pathname;
        if (strPath == null || strPath == '/') {
            return strFullPath;
        } else {
            var pos = strFullPath.indexOf(strPath);
            var prePath = strFullPath.substring(0, pos);
            // var postPath = strPath.substring(0,strPath.substring(1).indexOf("/")+1);
            return prePath;
        }
    }

    /*]]>*/
</script>
</body>

</html>